#ifndef THINK_TRAITS_THINK_INSTANCE_H
#define THINK_TRAITS_THINK_INSTANCE_H

static char* traits_think_instance =
	"\n"
	"// +----------------------------------------------------------------------\n"
	"// | ThinkPHP [ WE CAN DO IT JUST THINK ]\n"
	"// +----------------------------------------------------------------------\n"
	"// | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved.\n"
	"// +----------------------------------------------------------------------\n"
	"// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )\n"
	"// +----------------------------------------------------------------------\n"
	"// | Author: liu21st <liu21st@gmail.com>\n"
	"// +----------------------------------------------------------------------\n"
	"\n"
	"namespace traits\\think;\n"
	"\n"
	"use think\\Exception;\n"
	"\n"
	"trait Instance\n"
	"{\n"
	"    /**\n"
	"     * @var null|static 实例对象\n"
	"     */\n"
	"    protected static $instance = null;\n"
	"\n"
	"    /**\n"
	"     * 获取示例\n"
	"     * @param array $options 实例配置\n"
	"     * @return static\n"
	"     */\n"
	"    public static function instance($options = [])\n"
	"    {\n"
	"        if (null === self::$instance) {\n"
	"            self::$instance = new self($options);\n"
	"        }\n"
	"\n"
	"        return self::$instance;\n"
	"    }\n"
	"\n"
	"    /**\n"
	"     * 静态调用\n"
	"     * @param string $method 调用方法\n"
	"     * @param array  $params 调用参数\n"
	"     * @return mixed\n"
	"     * @throws Exception\n"
	"     */\n"
	"    public static function __callStatic($method, array $params)\n"
	"    {\n"
	"        if (null === self::$instance) {\n"
	"            self::$instance = new self();\n"
	"        }\n"
	"\n"
	"        $call = substr($method, 1);\n"
	"\n"
	"        if (0 !== strpos($method, \'_\') || !is_callable([self::$instance, $call])) {\n"
	"            throw new Exception(\'method not exists:\' . $method);\n"
	"        }\n"
	"\n"
	"        return call_user_func_array([self::$instance, $call], $params);\n"
	"    }\n"
	"}\n"
	"\n"
;
#endif